package com.nmf.pc.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nmf.dao.gen.bean.BizSysUser;
import com.nmf.pc.service.PcRegisterService;
import com.nmf.pc.vo.ReturnResult;
import com.nmf.pc.vo.UserRegisterVo;

@Controller
@RequestMapping(value = "/pc")
public class PcRegisterController {
	@Autowired
	PcRegisterService pcRegisterService;
	/**
	 * 获取分类
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = { "p/register" }, method = { RequestMethod.POST, RequestMethod.GET })
	public String register(HttpServletRequest request, HttpServletResponse response) {
		return "biz/register/register";
	}
	
	@ModelAttribute
	public UserRegisterVo get(HttpServletRequest request) {
		UserRegisterVo userRegisterVo = new UserRegisterVo();
		return userRegisterVo;
	}
	
	
	@RequestMapping(value = { "p/register/save" }, method = { RequestMethod.POST, RequestMethod.GET })
	public String save(@Valid UserRegisterVo userRegisterVo,BindingResult result,HttpServletRequest request, HttpServletResponse response) {
		pcRegisterService.registerUser(userRegisterVo);
		return "biz/register/register";
	}
	
	
	@RequestMapping(value = { "p/register/pcsave" }, method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ReturnResult pcsave(@Valid UserRegisterVo userRegisterVo,BindingResult result,HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		BizSysUser bizSysUser = pcRegisterService.registerUser(userRegisterVo);
		returnResult.setData("bizSysUser",bizSysUser);
		return returnResult;
		
	}
	
}
